const authBase = "http://localhost:9090";
const leaveBase = "http://localhost:9091";
const testBillBase = "http://localhost:9098";

const usernameExist = function (value) {
  return window.axios({
    method: "get",
    url: authBase + "/auth/userInfo/exist/" + value,
  });
};
const authInsert = function (account) {
  return window.axios({
    method: "post",
    url: authBase + "/auth/userInfo/insert",
    data: account,
  });
};

const login = function (username, password) {
  return window.axios({
    method: "post",
    url: authBase + "/login",
    data: `username=${username}&password=${password}`,
  });
};
const logout = function () {
  return window.axios({
    method: "post",
    url: authBase + "/logout",
  });
};
const getAllRoutes = function () {
  return window.axios({
    method: "get",
    url: authBase + "/auth/route/supplyAll",
  });
};
const getRoutesByCurrentUser = function () {
  return window.axios({
    method: "get",
    url: authBase + "/auth/route/supplyByUser",
  });
};

const auth = {
  usernameExist,
  authInsert,
  login,
  logout,
  getAllRoutes,
  getRoutesByCurrentUser,
  // bbb,
  // ccc,
};
const queryApply = function (searchForm) {
  return window.axios({
    method: "post",
    url: leaveBase + "/leave/leaveBill/query/apply",
    data: searchForm,
  });
};
const leaveInsert = function (leaveBill) {
  return window.axios({
    method: "post",
    url: leaveBase + "/leave/leaveBill/insert",
    data: leaveBill,
  });
};
const leaveTypes = function () {
  return window.axios({
    method: "get",
    url: leaveBase + "/leave/common/leaveTypes",
  });
};
const applyStates = function () {
  return window.axios({
    method: "get",
    url: leaveBase + "/leave/common/applyStates",
  });
};
const auditStates = function () {
  return window.axios({
    method: "get",
    url: leaveBase + "/leave/common/auditStates",
  });
};
const leaveModify = function (leaveBill) {
  return window.axios({
    method: "put",
    url: leaveBase + "/leave/leaveBill/modify",
    data: leaveBill,
  });
};
const findApply = function (id) {
  return window.axios({
    method: "get",
    url: leaveBase + "/leave/leaveBill/find/apply/" + id,
  });
};
const leaveSubmit = function (id) {
  return window.axios({
    method: "put",
    url: leaveBase + "/leave/leaveBill/submit/" + id,
  });
};
const findAudit = function (id) {
  return window.axios({
    method: "get",
    url: leaveBase + "/leave/leaveBill/find/audit/" + id,
  });
};
const auditSucceeded = function (leaveBill) {
  return window.axios({
    method: "put",
    url: leaveBase + "/leave/leaveBill/auditSucceeded",
    data: leaveBill,
  });
};
const auditFailed = function (leaveBill) {
  return window.axios({
    method: "put",
    url: leaveBase + "/leave/leaveBill/auditFailed",
    data: leaveBill,
  });
};

const leave = {
  queryApply,
  leaveInsert,
  leaveTypes,
  applyStates,
  auditStates,
  leaveModify,
  findApply,
  leaveSubmit,
  findAudit,
  auditSucceeded,
  auditFailed,
};
const queryMaterial = function () {
  return window.axios({
    method: "get",
    url: testBillBase + "/testBill/queryMaterial",
  });
};
const insertTestBill = function (testBill) {
  return window.axios({
    method: "post",
    url: testBillBase + "/testBill/insert",
    data: testBill,
  });
};
const testBill = {
  queryMaterial,
  insertTestBill,
};
export { auth, leave, testBill };
